// 同步钩子 -- 重复执行
class SyncLoopHook {
  // args => ['name']
  constructor(args) {
    this.tasks = [];
  }
  tap(name, task) {
    this.tasks.push(task);
  }
  call(...args) {
    this.tasks.forEach((task) => {
      let ret;
      do {
        ret = task(...args);
      } while (ret !== undefined);
    });
  }
}

let hook = new SyncLoopHook(["name"]);

let index = 0
hook.tap("node", (data) => {
  console.log("前端小溪(" + data + ") --- 学习node");
  return ++index === 3 ? undefined : "继续学";
});
hook.tap("react", (data) => {
  console.log("前端小溪(" + data + ") --- 学习react");
});
hook.tap("webpack", (data) => {
  console.log("前端小溪(" + data + ") --- 学习webpack");
});
hook.tap("vue", (data) => {
  console.log("前端小溪(" + data + ") --- 学习vue");
});

hook.call("xiaoxi");
